home *** CD-ROM | disk | FTP | other *** search
/ Champak 140 / (Vol 140) Sep 19 2011.iso / Games / theLifeArk.swf / scripts / __Packages / clock / Clock.as next >
Encoding:
Text File  |  2011-09-19  |  1.9 KB  |  86 lines

  1. class clock.Clock
  2. {
  3.    var dat;
  4.    var isRun;
  5.    var cttMc;
  6.    var intervalId;
  7.    static var duration = 1000;
  8.    static var modulo = 60;
  9.    static var hourMax = 10;
  10.    static var minuteMax = 0;
  11.    static var secondMax = 0;
  12.    function Clock()
  13.    {
  14.       this.dat = new Array();
  15.       this.dat = [0,0,0];
  16.       this.isRun = false;
  17.    }
  18.    function setCtt(p_cttMc)
  19.    {
  20.       this.cttMc = p_cttMc;
  21.    }
  22.    function executeCallback()
  23.    {
  24.       this.dat[2] = this.dat[2] + 1;
  25.       if(this.dat[2] == clock.Clock.modulo)
  26.       {
  27.          this.dat[2] = 0;
  28.          this.dat[1] = this.dat[1] + 1;
  29.          if(this.dat[1] == clock.Clock.modulo)
  30.          {
  31.             this.dat[1] = 0;
  32.             this.dat[0] = this.dat[0] + 1;
  33.          }
  34.       }
  35.       if(this.dat[0] >= clock.Clock.hourMax)
  36.       {
  37.          if(this.dat[1] >= clock.Clock.minuteMax)
  38.          {
  39.             if(this.dat[2] >= clock.Clock.secondMax)
  40.             {
  41.                this.stopClock();
  42.                _global.ctn.timeOut();
  43.             }
  44.          }
  45.       }
  46.       this.cttMc.refreshTime(this.dat);
  47.    }
  48.    function reStartClock()
  49.    {
  50.       this.stopClock();
  51.       var _loc2_ = 0;
  52.       while(_loc2_ < this.dat.length)
  53.       {
  54.          this.dat[_loc2_] = 0;
  55.          _loc2_ = _loc2_ + 1;
  56.       }
  57.       this.startClock();
  58.    }
  59.    function startClock()
  60.    {
  61.       if(this.isRun == false)
  62.       {
  63.          this.isRun = true;
  64.          this.cttMc.refreshTime(this.dat);
  65.          this.intervalId = setInterval(this,"executeCallback",clock.Clock.duration);
  66.          return undefined;
  67.       }
  68.       return undefined;
  69.    }
  70.    function stopClock()
  71.    {
  72.       this.isRun = false;
  73.       clearInterval(this.intervalId);
  74.       return undefined;
  75.    }
  76.    function getTime()
  77.    {
  78.       return this.dat.concat();
  79.    }
  80.    function setTime(pAry)
  81.    {
  82.       this.dat = pAry.concat();
  83.       this.cttMc.refreshTime(this.dat);
  84.    }
  85. }
  86.